import org.sugar.sigslot.Haxle;
using ListTools;

class Demo 
{



	public static function main(): Void
	{
		trace(here);
		var arr = haxe.Stack.callStack();
		for (i in arr){
			trace(i);
		}




		return;
		var l = new LeftWheel();
		var r = new RightWheel();
		trace('just the left wheel turns...');
		l.turn(1);

		Haxle.connect(l,'turn', r,'turn');
		trace('now both left and right...');
		l.turn(3);

		Haxle.disconnect(l,'turn', r, 'turn');
		trace('now just the left again...');
		l.turn(2);

	
		var m = new MiddleWheel();
		
		Haxle.connect(l, 'turn', m, 'turn');
		Haxle.connect(l, 'turn', m, 'turn');	
		
		trace('now the left once, and the middle wheel twice...');
		l.turn(1);

		var c = new CrookedWheel(); // crooked wheel has a different turn function()
		// we need to change the Leftwheel function arguments into something CrookedWheel can use with a mutator:
		var m = function(x:Array<Dynamic>){ return ['wobbling', x[0]];} // CrookedWheel turn(verb:String, x:Int)
		// now connect the crooked wheel with the mutator...
		Haxle.connect(l,'turn', c, 'turn', m );
		trace('now the left turns once, the middle one turns twice, and the crooked wheel wobbles once');
		l.turn(1);
		
		Haxle.disconnectAll(l);	// or disconnectAll(l,'turn'), disconnectAll(l,'turn', r).. etc.
		trace('disconnect everything from the left wheel, it turns once...');
		
		l.turn(7);
/*		trace('uh oh...'); 
		Haxle.connect(l,'turn', r, 'turn');
		Haxle.connect(r,'turn', l, 'turn');  // be careful not to form loops!
		l.turn(4);	*/
		
	}
	
	
}




class LeftWheel implements Dynamic {	// implement Dynamic (for Flash9) or...
/*class RightWheel implements HaxleStatic {*/ // implement HaxleStatic and..
/*	public var __haxle_slots:HaxleSlots;*/ // 	add the slot variable in manually if you don't want to use Dynamic Classes
	
	public function new(){}
	
	public function turn(x:Int){
		trace('left wheel is turning ' + x + ' times.');
		Haxle.signal(this,here.methodName,[x]);  	// you can now send signals with this static call
																// note that I'm not referencing any external class code here except for Haxle

	}
}

class RightWheel implements Dynamic{

	public function new(){}
		
	public function turn(x:Int){
		trace ('right wheel is turning ' + x + ' times.');
		Haxle.signal(this,here.methodName,[x]); // you can add another signal to create chains... or dangerous loops...
	
	}
	
	
	
}



class MiddleWheel {	

	public function new(){}
	
	public function turn(x:Int){
		trace('middle wheel is turning ' + x + ' times.');

	}
}

class CrookedWheel {	

	public function new(){}
	
	public function turn(verb:String, x:Int){
		trace('crooked wheel is ' + verb + ' ' + x + ' times.');

	}
}

